<template>
	<view>
		<navbar :title="$t('bank.add')" :background="$utypeprimary" :titleColor="$utitlecolor" :backColor="$utitlecolor">
		</navbar>
		<view class="box">
			<view class="code">
				<view class="code-font">
					{{$t("addbank.code")}}
				</view>
				<view class="select"  @click= "select">
					<template v-if="code">
						{{code}}
					</template>
					<view v-else style="font-size:28rpx;color:#a1777d;">
						{{$t('new.bankcodeph')}}
					</view>
					<u-select v-model="show" mode="single-column" :list="list" @confirm="confirm"></u-select>
				</view>	
			</view>
			<view class="code">
				<view class="code-font">
					{{$t("addbank.number")}}
				</view>
				<view class="code-right">
					<u-input v-model="number"  input-align="right"  placeholder-style="text-align:end"  :placeholder="$t('new.cardnumberph')" :clearable="false"/>
					<image v-show="number" style="width: 24rpx;height: 24rpx;margin-left: 30rpx" src="../../static/image/wrong.png"
					@click="clear('number')"></image>
				</view>
			</view>
			<view class="code">
				<view class="code-font">
					{{$t("addbank.name")}}
				</view>
				<view class="code-right">
					<u-input v-model="name"  input-align="right"  placeholder-style="text-align:end"  :placeholder="$t('new.cardholderph')" :clearable="false"/>
					<image v-show="name" style="width: 24rpx;height: 24rpx;margin-left: 30rpx" src="../../static/image/wrong.png"
					@click="clear('name')"></image>
				</view>
			</view>
			<view class="code">
				<view class="code-font">
					{{$t("addbank.information")}}
				</view>
				<view class="code-right">
					<u-input v-model="information"  input-align="right"  placeholder-style="text-align:end"  :placeholder="$t('new.contactph')" :clearable="false" />
					<image v-show="information" style="width: 24rpx;height: 24rpx;margin-left: 30rpx" src="../../static/image/wrong.png"
					@click="clear('information')"></image>
				</view>
			</view>
			<view class="code">
				<view class="code-font">
					{{$t("new.ifsc")}}
				</view>
				<view class="code-right">
					<u-input v-model="ifsc"  input-align="right"  placeholder-style="text-align:end"  :placeholder="$t('new.ifscph')" :clearable="false" />
					<image v-show="ifsc" style="width: 24rpx;height: 24rpx;margin-left: 30rpx" src="../../static/image/wrong.png"
					@click="clear('ifsc')"></image>
				</view>
			</view>
		</view>
		<view class="confirm" @click="confirm1" >
			{{$t("editadd.confirm")}}
		</view>
	</view>
</template>

<script>
	import {
		addbankcard,
		bankcodelist
	}from '@/api/bank.js'
	export default {
		data() {
			return {
				code:'',
				number:'',
				name:'',
				information:'',
				ifsc: '',
				show: false,
				list:[],
				values:''
			};
			
		},
		methods: {
			clear(key) {
				if(this.$data[key]){
					this.$data[key] = ''
				}
			},
			async confirm1(){
				uni.hideKeyboard();
				uni.showLoading({
				});
				setTimeout(async () => {
					let addbanks = await addbankcard({
						username : this.name,
						bankphone : this.information,
						bankname : this.values,
						bankcard : this.number,
						ifsc: this.ifsc
					})
					uni.hideLoading();
					console.log(addbanks),
					uni.navigateBack()
				}, 200);
			},
			async load(){
				let result = await bankcodelist()
				console.log(result)
				this.list = result
				
			},
			select(){
				this.show = true
			},
			confirm(e){
				console.log(e)
				this.values = e[0].value
				this.code = e[0].label
			}
			
		},
		onLoad() {
			this.load()
		}
	
	}
</script>
<style lang="scss">
	page{
		background-color: #F6F6F6FF;
	}
</style>
<style lang="scss" scoped>
	.box{
		width: 750rpx;
		background: #FFFFFF;
		font-size: 32rpx;
		font-family: Rubik;
		font-weight: 400;
		color: #2B3039;
		padding: 0 40rpx;
		.code{
			display: flex;
			justify-content: space-between;
			height: 108rpx;
			line-height: 108rpx;
			border-bottom: 2rpx solid  #ECECEC;
			.code-right{
				flex:1;
				display: flex;
				align-items: center;
				text-align: center;
			}
		}
	}
	.u-input{
		width: 300rpx;
	}
	.confirm{
		width: 670rpx;
		height: 90rpx;
		background: $u-type-primary;
		border-radius: 10rpx;
		font-size: 30rpx;
		font-family: Rubik;
		font-weight: 400;
		color: #fff;
		line-height: 90rpx;
		text-align: center;
		margin: 100rpx 40rpx 0;
	}
	.select{
		width: 360rpx;
		text-align: right;
		font-size: 32rpx;
		font-family: Rubik;
		font-weight: 400;
		color: #2B3039;
	}
</style>
